//
// Created by vcq on 21/4/2.
//
#include "model/flow.hpp"

static void GetFlow(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    basic_string_view<char> id = req.get_query_value("id");
    basic_string_view<char> plan = req.get_query_value("plan");
    basic_string_view<char> plan_id = req.get_query_value("plan_id");
    json item = MGetFlow(id, plan, plan_id);
    res.set_status_and_content(status_type::ok, item.dump(), req_content_type::json);
}

static void SaveFlow(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    struct flow flow1{};
    flow1.plan = atoi(req.get_query_value("plan").data());
    flow1.plan_id = atoi(req.get_query_value("plan_id").data());
    flow1.id = atoi(req.get_query_value("id").data());
    flow1.type = req.get_query_value("type");
    flow1.user_id = atoi(req.get_query_value("user_id").data());
    MAddFlow(flow1);
    res.set_status_and_content(status_type::ok);
}

static void DeleteFlow(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    MDeleteFlow(req.get_query_value("plan"), req.get_query_value("plan_id"), req.get_query_value("id"));
    res.set_status_and_content(status_type::ok);
}